package com.igeek.clud_system.controller;

import com.igeek.clud_system.dao.InformationDao;
import com.igeek.clud_system.entity.Club;
import com.igeek.clud_system.entity.Information;
import com.igeek.clud_system.entity.Student;
import com.igeek.clud_system.service.ClubService;
import com.igeek.clud_system.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class ClubAllController {
    @Autowired
    ClubService clubService;
    @Autowired
    StudentService studentService;

    @GetMapping("club/{name}/{type}/{statue}")
    public List<Club> getClub(@PathVariable("name")String name,@PathVariable("type")Integer type,@PathVariable("statue")Integer statue){
        List<Club> club = clubService.findClub(name, type,statue);
        return club;
    }

    @GetMapping("clubData/{clubId}")
    public Map<String,Object> getClubData(@PathVariable("clubId")Integer clubId){
        Map<String, Object> clubById = clubService.findClubById(clubId);
        return clubById;
    }

    @GetMapping("clubMain/{clubId}")
    public Map<String,Object> getClubMain(@PathVariable("clubId")Integer clubId){
        Map<String, Object> clubMain = clubService.findClubMain(clubId);
        return clubMain;
    }

    @GetMapping("clubStudents/{clubId}")
    public List<Student> getStudents(@PathVariable("clubId")Integer clubId){
        return clubService.findAllStudent(clubId);
    }

    @GetMapping("loginClubStudent/{studentId}/{clubId}")
    public Student getSta(@PathVariable("studentId")Integer studentId, @PathVariable("clubId")Integer clubId){
        Student man = clubService.getMan(clubId, studentId);
        return man;
    }

    @PostMapping("setMan/{role}/{clubId}/{studentId}")
    public void setClubMan(@PathVariable("role")Integer role,@PathVariable("studentId")Integer studentId, @PathVariable("clubId")Integer clubId){
        studentService.updateMan(role,clubId,studentId);
    }

    @PostMapping("deleStu/{clubId}/{studentId}")
    public void delStu(@PathVariable("studentId")Integer studentId, @PathVariable("clubId")Integer clubId){
        studentService.deleteClubMan(clubId,studentId);
    }

    @PostMapping("approve/{requestId}")
    public void approve(@PathVariable("requestId")Integer requestId){
        clubService.approve(requestId);
    }

    @PostMapping("reject/{requestId}")
    public void reject(@PathVariable("requestId")Integer requestId){
        clubService.reject(requestId);
    }

    @GetMapping("information/{studentId}")
    public List<Information> getInfor(@PathVariable("studentId")Integer studentId){
        List<Information> infor = clubService.infor(studentId);
        return infor;

    }}
